
# 读文件，读整个文件
def read():
    file = open("000.txt",encoding="UTF-8")
    text = file.read()
    print(text)
    file.close()

# 按行读文件
def read_line():
    file = open("000.txt", encoding="UTF-8")
    while True:
        text = file.readline()

        if not text:
            break

        # end="" : 不让print自动换行
        print(text,end="")

# 写文件
def write():
    file = open("000.txt","a",encoding="UTF-8")
    file.write("new line" + "\n")
    file.write("new line2")
    file.close()

# 复制文件
def copy(sourceFile,targetFile):
    source = open(sourceFile,encoding="UTF-8")
    target = open(targetFile,"w",encoding="UTF-8")

    while True:
        text = source.readline()

        if not text:
            break

        # 消除换行符
        target.write(text.replace("\n",""))

    source.close()
    target.close()

import os
if __name__ == "__main__":
    copy("000.txt","0000.txt")
    # 重命名
    os.rename("0000.txt","00.txt")
    # 删除
    os.remove("00.txt")
    # 目录列表
    print(os.listdir())
    # 新建文件夹
    os.mkdir("temp")
    # 删除文件夹
    os.rmdir("temp")
    # get current work dir
    print(os.getcwd())
    